home *** CD-ROM | disk | FTP | other *** search
/ Oxygen Multimedia Graphics 22 / Oxygen Multimedia Graphics 22.iso / pc / System / OX22 / Internal_29_Cycle Graphics.ls < prev    next >
Encoding:
Text File  |  2008-03-12  |  11.0 KB  |  277 lines

  1. property spriteNum, mySprite, myFirstMember, myLastMember, myFrameTime, myTimeUnit, myPlayBackwards, myMembersList, myMemberCount, myCurrentMember, myListPosition, myLoopFlag, myMilliseconds
  2.  
  3. on getBehaviorDescription me
  4.   return "CYCLE GRAPHICS" & RETURN & RETURN & "This behavior cycles through a series of consecutive cast members." & RETURN & RETURN & "It gives you all the features of a single member filmloop, plus the possibility of precise control via Lingo. " & "These possibilities include speed control, starting and stopping at an arbitrary image, modifying the list of images to cycle through and more. " & "(See Public Methods below.)" & RETURN & RETURN & "You simply arrange your castmembers in the order they should appear in the cycle, then use the Parameters dialog to indicate the first and last images. " & "You can use any type of graphic member. " & "Spaces between cast members will be ignored." & RETURN & RETURN & "The registration point of each member will appear at the location of the current sprite. " & "If necessary, modify the registration point of each member individually so that it appears in the correct position relative to the other members of the cycle." & RETURN & RETURN & "If you shift the members to different cast slots, you will need to alter the settings in the Parameters dialog: a film loop can keep track of where you drag its members to, but this behavior cannot do that." & RETURN & RETURN & "The images cannot cycle faster than the current frame tempo. " & "If you need to cycle faster, either increase the tempo or reduce the number of images in the list. " & "At speeds of more than 60 images per second, the human eye is incapable of distinguishing individual images, so higher speeds are unnecessary." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "bitmap, button, field, filmloop, Flash, Director movie," & RETURN & "QuickTime, shape, text, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* First member of series" & RETURN & "* Last member of series" & RETURN & "* Maximum speed" & RETURN & "* Cycle direction (forwards or backwards)" & RETURN & "* Start cycling on beginsprite" & RETURN & RETURN & "If you choose not to start cycling images on beginsprite, then you need to send a CycleGraphics_ToggleLoop message to the sprite or the behavior to make the cycle start." & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "* Determine which image is currently showing" & RETURN & "* Cycle images at the frameTempo or slower" & RETURN & "* Play the images forwards or backwards" & RETURN & "* Start and stop at an arbitrary image" & RETURN & "* Jump to a given image" & RETURN & "* Determine or modify the list of images to cycle through" & RETURN & "* Obtain the behavior reference"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with any graphic member." & RETURN & RETURN & "Cycles a sprite through a series of images at a rate independent of the frame tempo." & RETURN & RETURN & "This behavior gives you all the features of a single member filmloop, plus precise control via Lingo. " & "You can stop/start the cycle, alter the speed, jump to an arbitrary member, reverse the direction of the cycle, get and set the list of members to cycle through, and determine which image is currently showing." & RETURN & RETURN & "See the Notes for Developers in the script for more details."
  9. end
  10.  
  11. on beginSprite me
  12.   myTimeUnit = resolve(myTimeUnit)
  13.   myPlayBackwards = resolve(myPlayBackwards)
  14.   Initialize(me)
  15. end
  16.  
  17. on resolve prop
  18.   case prop of
  19.     myTimeUnit:
  20.       choiceslist = ["Images Per Second", "Ticks Per Image", "Seconds Per Image", "Minutes Per Image"]
  21.       lookup = ["images per second", "ticks per image", "seconds per image", "minutes per image"]
  22.     myPlayBackwards:
  23.       choiceslist = ["Forwards", "Backwards"]
  24.       lookup = [#forwards, #backwards]
  25.   end case
  26.   return lookup[findPos(choiceslist, prop)]
  27. end
  28.  
  29. on prepareFrame me
  30.   update(me)
  31. end
  32.  
  33. on Initialize me
  34.   mySprite = sprite(me.spriteNum)
  35.   case myTimeUnit of
  36.     "images per second":
  37.       myFrameTime = 1000 / myFrameTime
  38.     "ticks per image":
  39.       myFrameTime = myFrameTime * 1000 / 60
  40.     "seconds per image":
  41.       myFrameTime = myFrameTime * 1000
  42.     "minutes per image":
  43.       myFrameTime = myFrameTime * 1000 * 60
  44.   end case
  45.   case myPlayBackwards of
  46.     #forwards:
  47.       myPlayBackwards = 0
  48.     #backwards:
  49.       myPlayBackwards = 1
  50.     otherwise:
  51.       return #invalidSymbolError
  52.   end case
  53.   myFirstMember = member(myFirstMember)
  54.   myLastMember = member(myLastMember)
  55.   minMember = min(myFirstMember.number, myLastMember.number)
  56.   maxMember = max(myFirstMember.number, myLastMember.number)
  57.   myMembersList = []
  58.   repeat with memberNumber = minMember to maxMember
  59.     theMember = member(memberNumber)
  60.     myMembersList.append(theMember)
  61.   end repeat
  62.   checkedList = StripNonGraphicMembers(me, duplicate(myMembersList))
  63.   if checkedList <> myMembersList then
  64.     ErrorAlert(me, #invalidMembers)
  65.     myMembersList = checkedList
  66.   end if
  67.   myMemberCount = myMembersList.count()
  68.   myListPosition = 1
  69.   myMilliseconds = the milliSeconds
  70. end
  71.  
  72. on update me
  73.   if not myLoopFlag then
  74.     exit
  75.   end if
  76.   elapsedTime = the milliSeconds - myMilliseconds
  77.   if abs(elapsedTime < myFrameTime) then
  78.     exit
  79.   else
  80.     if elapsedTime > (myFrameTime * 2) then
  81.       myMilliseconds = the milliSeconds
  82.     end if
  83.   end if
  84.   myMilliseconds = myMilliseconds + myFrameTime
  85.   if myPlayBackwards then
  86.     myListPosition = myListPosition - 2 + myMemberCount
  87.   end if
  88.   myListPosition = (myListPosition mod myMemberCount) + 1
  89.   myCurrentMember = myMembersList[myListPosition]
  90.   mySprite.member = myCurrentMember
  91. end
  92.  
  93. on CycleGraphics_GetCurrentMember me
  94.   return myCurrentMember
  95. end
  96.  
  97. on CycleGraphics_GetMembersList me
  98.   return myMembersList
  99. end
  100.  
  101. on CycleGraphics_ToggleLoop me, trueOrFalse
  102.   if voidp(trueOrFalse) then
  103.     myLoopFlag = not myLoopFlag
  104.   else
  105.     if ilk(trueOrFalse) <> #integer then
  106.       return #invalidTypeError
  107.     else
  108.       myLoopFlag = trueOrFalse
  109.     end if
  110.   end if
  111.   if myLoopFlag then
  112.     myMilliseconds = the milliSeconds
  113.   end if
  114. end
  115.  
  116. on CycleGraphics_ToggleDirection me, playBackwards
  117.   if voidp(playBackwards) then
  118.     myPlayBackwards = not myPlayBackwards
  119.   else
  120.     case playBackwards of
  121.       #forward, #forwards, 0:
  122.         myPlayBackwards = 0
  123.       #back, #backward, #backwards, #reverse, 1:
  124.         myPlayBackwards = 1
  125.       otherwise:
  126.         return #invalidSymbolError
  127.     end case
  128.   end if
  129.   myMilliseconds = the milliSeconds
  130. end
  131.  
  132. on CycleGraphics_ShowImage me, theImage
  133.   case ilk(theImage) of
  134.     #integer:
  135.       if (theImage < 1) or (theImage > myMemberCount) then
  136.         return #outOfRangeError
  137.       else
  138.         myListPosition = theImage
  139.         myCurrentMember = myMembersList[myListPosition]
  140.       end if
  141.     #member:
  142.       listPosition = myMembersList.getPos(theImage)
  143.       if listPosition then
  144.         myCurrentMember = theImage
  145.         myListPosition = listPosition
  146.       else
  147.         return #notInListError
  148.       end if
  149.     otherwise:
  150.       return #invalidTypeError
  151.   end case
  152.   mySprite.member = myCurrentMember
  153.   myMilliseconds = the milliSeconds
  154.   updateStage()
  155. end
  156.  
  157. on CycleGraphics_SetFrameTime me, theMilliseconds
  158.   if ilk(theMilliseconds) <> #integer then
  159.     return #invalidTypeError
  160.   else
  161.     if ilk(theMilliseconds) < 0 then
  162.       return #outOfRangeError
  163.     end if
  164.   end if
  165.   myFrameTime = theMilliseconds
  166. end
  167.  
  168. on CycleGraphics_SetMembersList me, membersList
  169.   if ilk(membersList) <> #list then
  170.     return #invalidTypeError
  171.   end if
  172.   StripNonGraphicMembers(me, membersList)
  173.   if not membersList.count() then
  174.     return #emptyListError
  175.   end if
  176.   myMembersList = membersList
  177.   myMemberCount = myMembersList.count()
  178.   if myPlayBackwards then
  179.     myListPosition = 1
  180.   else
  181.     myListPosition = myMemberCount
  182.   end if
  183. end
  184.  
  185. on CycleGraphics_GetReference me, theList
  186.   case ilk(theList) of
  187.     #list:
  188.       theList.append(me)
  189.     #propList:
  190.       theList.addProp(me.spriteNum, me)
  191.     otherwise:
  192.       return me
  193.   end case
  194.   return theList
  195. end
  196.  
  197. on StripNonGraphicMembers me, membersList
  198.   permittedTypes = [#bitmap, #button, #field, #filmLoop, #flash, #movie, #picture, #quickTimeMedia, #shape, #text, #vectorShape]
  199.   i = membersList.count()
  200.   repeat while i
  201.     theMember = membersList[i]
  202.     if ilk(theMember) <> #member then
  203.       membersList.deleteAt(i)
  204.     else
  205.       if not permittedTypes.getPos(theMember.type) then
  206.         membersList.deleteAt(i)
  207.       end if
  208.     end if
  209.     i = i - 1
  210.   end repeat
  211.   return membersList
  212. end
  213.  
  214. on ErrorAlert me, theError, data
  215.   behaviorName = string(me)
  216.   delete word 1 of behaviorName
  217.   delete char -30001 of behaviorName
  218.   delete char -30001 of behaviorName
  219.   case data.ilk of
  220.     #void:
  221.       data = "<void>"
  222.     #symbol:
  223.       data = "#" & data
  224.   end case
  225.   case theError of
  226.     #invalidMembers:
  227.       if the runMode <> "Author" then
  228.         exit
  229.       end if
  230.       message = substituteStrings(me, "BEHAVIOR ERROR: Frame ^0, Sprite ^1" & RETURN & "Behavior ^2" & RETURN & "Certain members between ^3 and ^4 were not graphical members so they will not be displayed. " & "Check the permitted types list for valid types.", ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": myFirstMember, "^4": myLastMember])
  231.       alert(message)
  232.   end case
  233. end
  234.  
  235. on substituteStrings me, parentString, childStringList
  236.   i = childStringList.count()
  237.   repeat while i
  238.     tempString = EMPTY
  239.     dummyString = childStringList.getPropAt(i)
  240.     replacement = childStringList[i]
  241.     lengthAdjust = dummyString.char.count - 1
  242.     repeat while 1
  243.       position = offset(dummyString, parentString)
  244.       if not position then
  245.         parentString = tempString & parentString
  246.         exit repeat
  247.         next repeat
  248.       end if
  249.       if position <> 1 then
  250.         tempString = tempString & parentString.char[1..position - 1]
  251.       end if
  252.       tempString = tempString & replacement
  253.       delete parentString.char[1..position + lengthAdjust]
  254.     end repeat
  255.     i = i - 1
  256.   end repeat
  257.   return parentString
  258. end
  259.  
  260. on isOKToAttach me, aSpriteType, aSpriteNum
  261.   case aSpriteType of
  262.     #graphic:
  263.       return getPos([#bitmap, #button, #field, #filmLoop, #flash, #movie, #picture, #quickTimeMedia, #shape, #text, #vectorShape], sprite(aSpriteNum).member.type) <> 0
  264.     #script:
  265.       return 0
  266.   end case
  267. end
  268.  
  269. on getPropertyDescriptionList
  270.   if not (the currentSpriteNum) then
  271.     exit
  272.   end if
  273.   theMember = sprite(the currentSpriteNum).member
  274.   theMemberNumber = theMember.number
  275.   return [#myFirstMember: [#comment: "First member of series", #format: #graphic, #default: theMember], #myLastMember: [#comment: "Last member of series", #format: #graphic, #default: member(theMemberNumber + 1)], #myFrameTime: [#comment: "Display images at a maximum speed of", #format: #integer, #range: [#min: 1, #max: 120], #default: min(the frameTempo, 120)], #myTimeUnit: [#comment: EMPTY, #format: #string, #range: ["Images Per Second", "Ticks Per Image", "Seconds Per Image", "Minutes Per Image"], #default: "Images Per Second"], #myPlayBackwards: [#comment: "Cycle", #format: #string, #range: ["Forwards", "Backwards"], #default: "Forwards"], #myLoopFlag: [#comment: "Start cycling on beginSprite?", #format: #boolean, #default: 1]]
  276. end
  277.